package com.miyuan.wm.controller;

import com.alibaba.fastjson.JSON;
import com.miyuan.wm.data.UserInfo;
import com.miyuan.wm.request.AddRecordInRequestVo;
import com.miyuan.wm.request.AddRecordOutRequestVo;
import com.miyuan.wm.request.QueryRecordInOutRequestVo;
import com.miyuan.wm.response.BaseResponse;
import com.miyuan.wm.response.PageResponse;
import com.miyuan.wm.response.QueryRecordInOutResponseVo;
import com.miyuan.wm.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName RecordController
 * @Description 出入库管理控制器
 */
@RestController
@Api(description = "出入库管理控制器", tags = {"出入库管理"})
@RequestMapping(value = "/record")
@Slf4j
public class RecordController {

    @Autowired
    private RecordService recordService;

    @ApiOperation(value = "货物入库接口")
    @PostMapping("/addRecordIn")
    public BaseResponse<Boolean> addRecordIn(@Valid @RequestBody AddRecordInRequestVo requestVo) {
        log.info("货物入库接口请求参数：{}", JSON.toJSONString(requestVo));
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getSession().getAttribute("userInfo");
        return recordService.addRecordIn(userInfo, requestVo);
    }

    @ApiOperation(value = "货物出库接口")
    @PostMapping("/addRecordOut")
    public BaseResponse<Boolean> addRecordOut(@Valid @RequestBody AddRecordOutRequestVo requestVo) {
        log.info("货物出库接口请求参数：{}", JSON.toJSONString(requestVo));
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getSession().getAttribute("userInfo");
        return recordService.addRecordOut(userInfo, requestVo);
    }

    @ApiOperation(value = "查询货物出入库记录接口")
    @PostMapping("/listRecordInOut")
    public PageResponse<List<QueryRecordInOutResponseVo>> listRecordInOut(@Valid @RequestBody QueryRecordInOutRequestVo requestVo) {
        log.info("查询货物出入库记录接口请求参数：{}", JSON.toJSONString(requestVo));
        return recordService.listRecordInOut(requestVo);
    }

}
